const Koa = require('koa')
const app = new Koa()
const router = require('./routes')
const views = require('koa-views')
const serve = require('koa-static')

// 挂载静态页面并载入ejs
app.use(views(__dirname + '/views', {
  map: {
    html: 'ejs'
  }
}))

// 访问静态资源
app.use(serve(__dirname + '/static'))
// 中间件
app.use(async (ctx, next) => {
  const host = '';
  // const host = ctx.request.header.host;
  ctx.config = {
    host,
    version: '1.0.0',
    title: '长虹职业技能培训学校',
    description: '长虹职业技能培训学校',
    keyword: '长虹职业技能培训学校',
    // 荣誉资质
    honor: [{
      id: 1,
      title: '创业云星',
      src: `${host}/imgs/honor5.jpg`
    }, {
      id: 2,
      title: '拥军优属先进单位',
      src: `${host}/imgs/honor6.jpg`
    }, {
      id: 3,
      title: '劳动用工诚信单位',
      src: `${host}/imgs/honor8.jpg`
    }]
  }
  await next()
})

// 挂载路由
app.use(router.routes()).use(router.allowedMethods())

// 配置服务
app.listen(3005, () => {
  console.log('server is running http://localhost:3005')
})